//
//  ECUITVCell_CourseComment.m
//  Edu_iOS2018
//
//  Created by yanyan on 2018/1/17.
//  Copyright © 2018年 yanyan. All rights reserved.
//

#import "ECUITVCell_CourseComment.h"
#import "ECLevelView.h"
#import "ECCourseCommentModel.h"
@interface ECUITVCell_CourseComment()
{
    ///头像image
    UIImageView *iconImage;
    ///星星image
    UIImageView *starImage;
    ///课程名lab
    UILabel *titleLab;
    ///时间lab
    UILabel *timeLab;
    ///内容lab
    UILabel *contentLab;
}
//@property(nonatomic,strong)UIImageView *avatarView;
//@property(nonatomic,strong)UILabel *nameLabel;
//@property(nonatomic,strong)UILabel *timeLabel;
//@property(nonatomic,strong)UILabel *contentLabel;
//@property (nonatomic,strong)ECLevelView *levelView;

@end
@implementation ECUITVCell_CourseComment

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)addSubviews
{
    [super addSubviews];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    CGFloat imageHeight = kProportion_Height(108);
    iconImage = [[UIImageView alloc]init];
    iconImage.layer.masksToBounds = YES;
    iconImage.layer.cornerRadius = imageHeight / 2.0;
    [self.contentView addSubview:iconImage];
    
    titleLab = [[UILabel alloc]init];
    [self.contentView addSubview:titleLab];
    titleLab.font = [UIFont systemFontOfSize:15*kPercentage];
    titleLab.textColor = [UIColor colorWithHexString:@"#454545"];
    
    starImage = [[UIImageView alloc]init];
    [self.contentView addSubview:starImage];
    
    timeLab = [[UILabel alloc]init];
    [self.contentView addSubview:timeLab];
    timeLab.font = [UIFont systemFontOfSize:10*kPercentage];
    timeLab.textColor = [UIColor colorWithHexString:@"#BFBFBF"];
    
    contentLab = [[UILabel alloc]init];
    [self.contentView addSubview:contentLab];
    contentLab.numberOfLines = 0;
    contentLab.font = [UIFont systemFontOfSize:13*kPercentage];
    contentLab.textColor = [UIColor colorWithHexString:@"#6D7689"];
    
    WeakSelf(weakSelf);
    CGFloat hpadding = kProportion_Width(45);
    [iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView).offset(hpadding);
        make.top.equalTo(weakSelf.contentView).offset(kProportion_Height(60));
        make.width.height.equalTo(@(kProportion_Height(108)));
    }];
    
    [starImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.contentView.mas_right).offset(-kProportion_Width(45));
        make.centerY.equalTo(titleLab.mas_centerY);
        make.width.equalTo(@(kProportion_Width(200)));
        make.height.equalTo(starImage.mas_width).multipliedBy(24.f/131.f);
    }];
    
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconImage.mas_right).offset(kProportion_Width(36));
        make.right.equalTo(starImage.mas_left).offset(kProportion_Width(45));
        make.top.equalTo(iconImage.mas_top);
//        make.height.equalTo(@16);
    }];
    
    [timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLab.mas_left);
        make.bottom.equalTo(iconImage.mas_bottom);
        make.width.equalTo(titleLab.mas_width);
        make.height.equalTo(@15);
    }];
    
    [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(timeLab.mas_bottom).offset(kProportion_Height(35));
        make.left.equalTo(titleLab.mas_left);
        make.right.equalTo(starImage.mas_right);
        make.bottom.equalTo(weakSelf.contentView).offset(-kProportion_Height(30));
    }];
    
}
-(void)setObject:(id)object
{
    [super setObject:object];
    ECCourseCommentModel *mo = object;
    [iconImage sd_setImageWithURL:[NSURL URLWithString:mo.user.avatarUrl] placeholderImage:[UIImage imageNamed:@"Mine_iconImage"]];
    titleLab.text = mo.user.showName;
    timeLab.text = mo.createdTime;
    contentLab.text = mo.content.length > 0?mo.content:@"此用户没有填写评价";
    //根据不同数字 加载不同评价级别图片
    switch (mo.rating) {
        case 1:
            starImage.image = [UIImage imageNamed:@"Mine_star_one"];
            break;
        case 2:
            starImage.image = [UIImage imageNamed:@"Mine_star_two"];
            break;
        case 3:
            starImage.image = [UIImage imageNamed:@"Mine_star_three"];
            break;
        case 4:
            starImage.image = [UIImage imageNamed:@"Mine_star_four"];
            break;
        case 5:
            starImage.image = [UIImage imageNamed:@"Mine_star_five"];
            break;
        default:
            starImage.image = [UIImage imageNamed:@"Mine_star_zero"];
            break;
    }
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
